{block name="content"}
{include file='control/claim/formstyle'}
<form action="{:request()->url()}" autocomplete="off" class="layui-form layui-card" data-auto="true" method="post">
    <div class="layui-card-body">
        <div style="display: flex;">
            <div class="layui-form-item relative block layui-col-xs4" style="margin-left: 40px">
                <span class="color-green font-w7">业务科室</span>
                <span class="color-desc margin-left-5">Yewu Keshi</span>
                <select name="keshi_id">
                    <!--<option value="">- 无 -</option>-->
                    {volist name='keshi_list' id='ks'}
                    <option value="{$ks.id}">- {$ks.nickname}({$ks.username}) -</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-item relative block layui-col-xs4" style="margin-left: 40px">
                <span class="color-green font-w7">精益化管理部</span>
                <span class="color-desc margin-left-5">Gongying Kezhang</span>
                <select name="jingyi_id">
                    <!--<option value="">- 无 -</option>-->
                    {volist name='jingyi_list' id='gy'}
                    <option value="{$gy.id}">- {$gy.nickname}({$gy.username}) -</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item  padding-left-40">
            <div class="relative block">
                <div style="display: flex;justify-content: space-between;">
                    <div>
                        <span class="color-green font-w7">物资数据</span>
                        <span class="color-desc margin-left-5">Storehouse Data</span>
                    </div>
                    <div class="color-green font-w7 text-right" id="get_cate_list" style="padding: 6px 16px;background-color: #009688;color: #fff !important;cursor:pointer">选择物资</div>
                </div>
                <table class="layui-table margin-top-12" lay-skin="line" id='dataInfo' lay-filter="demo">
                    <thead>
                    <tr>
                        <th class="text-center">编号</th>
                        <th class="text-center">名称</th>
                        <th class="text-center">规格</th>
                        <th class="text-center">单位</th>
                        <th class="text-center">单价</th>
                        <th class="text-center">数量</th>
                        <th class="text-center">总价</th>
                        <!--<th class="text-center"></th>-->
                    </tr>
                    </thead>
                    <tbody id="one_add">
                    <style>
                        td input{width:100%;height:28px;text-align: center;border: none;}
                    </style>
                    <tr>
                    </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <div class="hr-line-dashed"></div>
    <div class="layui-form-item text-center">
        <button class="layui-btn" type='submit'>保存</button>
        <button class="layui-btn layui-btn-danger" data-close data-confirm="确定要取消吗？" type='button'>取消</button>
    </div>
</form>

<script>
    form.render()
    var infoJson = []
    // 删除按钮事件
    $(document).on('click','.editdelete',function () {
        $(this).parents('tr').remove();
        var index = $(this).parents('tr').find('a').data('index');
        infoJson.splice(index,1);
        console.log(infoJson)
    })
    //获取小计价格
    $(document).on('input',"input[type='number']",function () {
        //获取单价
        var price = $(this).parent().prev().find('input').val();
        var num = $(this).val()
        var aaa = price * num;
        var xjprice = $(this).parent().next().find('input').val(Math.round(aaa*100)/100);
    })
    var tabIndex = 0
    //获取选中数据
    $("#get_cate_list").on('click', function(){
        var url = "#data/control.lists/cliam_data?spm="+"{$_GET['spm']}"
        var title = '仓库数据'
        layer.open({
            type: 2,
            title: title+'列表',
            area: ['80%', '600px'],
            fixed: true, //不固定
            maxmin: false,
            content: url,
            btn: ['获取选中的'+title, '关闭'],
            btnclass: ['btn btn-primary', 'btn btn-danger'],
            yes: function (index, layero) {
                var infoJson = JSON.parse(localStorage.getItem("{$userId}"));
                // tem = JSON.parse(tem);
                // for (var i = 0; i < tem.length;i++) {
                //     infoJson.push(tem[i])
                // }
                tabIndex = tabIndex+infoJson.length
                PicCallBack(infoJson);
                parent.layer.close(index);
            }, cancel: function () {
                return true;
            }
        });
        function PicCallBack(data){
            console.log(data)
            var html = ''
            //渲染数据
            for (var i = 0; i < data.length;i++) {
                console.log()
                html +=
                // "<tr><input  type='hidden'  name='storehouse_item_id[]' value="+data[i].id+">\n"+
                    "<tr><input  type='hidden'  name='cate_id[]' value="+data[i].cate_id+">\n"+
                    "<td class='text-center'><input style='border:none;height:28px;text-align: center;' type='text' readonly name='material_code[]' value="+data[i].material_code+"></td>" +
                    "<td class='text-center'><input type='text' style='border:none;height:28px;text-align: center;' readonly name='material_name[]' value='"+data[i].material_name+"'></td>\n" +
                    "<td class='text-center'><input type='text' style='border:none;height:28px;text-align: center;' readonly name='material_model[]' value='"+data[i].material_model+"'></td>\n" +
                    "<td class='text-center'><input type='text' style='border:none;height:28px;text-align: center;' readonly name='material_unit[]' value="+data[i].material_unit+"></td>\n" +
                    "<td class='text-center'><input type='text' style='border:none;height:28px;text-align: center;' readonly name='material_price[]' value="+data[i].material_price+"></td>\n" +
                    "<td class='text-center'><input type='number' style='text-align: center;height:28px;' name='ex_num[]' readonly value="+ Number(data[i].ex_num)+" tabindex="+ Number(i.tabIndex)+"></td>\n" +
                    "<td class='text-center'><input type='text' style='border:none;height:28px;text-align: center;' readonly name='material_xjprice[]' value="+ Number(data[i].ex_num * data[i].material_price)+"></td>\n" 
                    // "<td class='text-center'><a class='editdelete' style='border:1px solid #ccc;' data-index="+i+">删除</a></td></tr>"
            }
            // infoJson = []
            $("#one_add").html(html)
            //清空缓存
            localStorage.removeItem("{$userId}")
            form.render();
        }

    });

</script>

{/block}